<link rel="stylesheet" href="${baseStaticUrl}/plugins/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="${baseStaticUrl}/plugins/ztree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="${baseStaticUrl}/plugins/ztree/js/jquery.ztree.excheck.js"></script>
<div class="form-container">
	<div class="box">
        <form action="#" method="post" name="suvForm" id="suvForm">
        	<div class="row visa-row">
                <div id="wait-msg" class="alert alert-info"
                     style="background:url(${baseStaticUrl}/images/ajax-loader.gif) no-repeat scroll 0.5em 50%;display:none"></div>
                <div id="alert-msg" class="alert alert-success" style="display:none"></div>
                <div id="error-msg" class="alert alert-danger" style="display:none"></div>
            </div>
            <div class="row visa-row">
            	<h6 class="mg-b-20 h6-mar-sm">
                    <strong>菜单管理</strong>
                </h6>
                <div class="row w-row">
                	<div class="col-md-1 col-xs-12 w-row1">父级菜单</div>
                    <div class="col-md-3 col-xs-12 w-row2">
                         <input type="hidden" class="form-control form-control-sm" id="fjcd" name="sysMenu.PARENT_ID" value="${parentId!sysMenu.PARENT_ID}"/>
                         <div class="tdself">
                         		<input type="text" class="form-control form-control-sm" id="fjcdName" readonly="readonly" value="${parentName!sysMenu.PARENT_ID}"/>
                         		<span class="btn visa-btn-icon visa-btn-select fa fa-search fa-1" data-toggle="modal"
		                                data-target="#selectMenuModal"
		                                aria-hidden="true"></span>
                         </div>
                     </div>
                     <div class="col-md-1 col-xs-12 w-row1"><span class="span_red">*</span>菜单名称</div>
                    <div class="col-md-3 col-xs-12 w-row2 colself">
                         <input type="text" class="form-control form-control-sm" id="cdmc" name="sysMenu.MENU_NAME" value="${sysMenu.MENU_NAME}" onchange="verifyName();"/>
                         <input type="hidden" name="sysMenu.ID" value="${sysMenu.ID}" id="ID"/>
                     </div>
                     <div class="col-md-1 col-xs-12 w-row1"><span class="span_red">*</span>菜单URL</div>
                     <div class="col-md-3 col-xs-12 w-row2"><input type="text" class="form-control form-control-sm" id="cdurl" name="sysMenu.MENU_URL" value="${sysMenu.MENU_URL}"/>
                     </div>
                </div>
                <div class="row w-row">
                       <div class="col-md-1 col-xs-12 w-row1"><span class="span_red">*</span>状态</div>
                       <div class="col-md-3 col-xs-12 w-row2"><epoch:radio name="sysMenu.STATUS" id="cdzt" list="${lisFun.getDictCode('PUB_ENABLE_DISABLE')}"
                                checked="${sysMenu.STATUS!=null ? sysMenu.STATUS:'ENABLE' }"></epoch:radio></div>
                       <div class="col-md-1 col-xs-12 w-row1">菜单图标</div>
                       <div class="col-md-3 col-xs-12 w-row2"><input type="text" class="form-control form-control-sm" name="sysMenu.MENU_ICON" value="${sysMenu.MENU_ICON}"/></div>
                       <div class="col-md-1 col-xs-12 w-row1"><span class="span_red">*</span>菜单类型</div>
                       <div class="col-md-3 col-xs-12 w-row2"><epoch:select list="${lisFun.getDictCode('SYS_MENU_TYPE')}" name="sysMenu.MENU_TYPE" id="cdlx" value="${sysMenu.MENU_TYPE!}"></epoch:select></div>
                </div>
                <div class="row w-row">
                    <div class="col-md-1 col-xs-12 w-row1"><span class="span_red">*</span>菜单序号</div>
                    <div class="col-md-3 col-xs-12 w-row2"><input type="text" id="cdss" class="form-control form-control-sm" name="sysMenu.MENU_ORDER" value="${sysMenu.MENU_ORDER!}"/></div>
                    <div class="col-md-1 col-xs-12 w-row1"><span class="span_red">*</span>菜单编码</div>
                    <div class="col-md-3 col-xs-12 w-row2"><input type="text" id="menuCodeId" onchange="verifyMenuCode();" class="form-control form-control-sm" name="sysMenu.MENU_CODE" 
                        value="${sysMenu.MENU_CODE!}"/></div>
                    <div class="col-md-1 col-xs-12 w-row1"></div>
                    <div class="col-md-3 col-xs-12 w-row2"></div>
                </div>
                <div class="row w-row">
                    <div class="col-md-1 col-xs-12 w-row1">描述</div>
                    <div class="col-md-11 col-xs-12 w-row2"><textarea rows="4" cols="129" id="ms" style="resize:none;" name="sysMenu.COMMENTS" class="form-control form-control-sm"
                        maxlength="200">${sysMenu.COMMENTS}</textarea></div>
                </div>
                <div class="row w-row">
                    <div class="col-md-1 col-xs-12 w-row1">分配角色</div>
                    <div class="col-md-11 col-xs-12 w-row2">
                         <input name="userRole" type="hidden" id="userRole" value="${sysMenu.menuRole!}"/>
                         <textarea rows="10" cols="129" id="selectRoleText" style="resize:none;" data-toggle="modal" class="form-control form-control-sm"
                             data-target="#selectRoleModal" readonly="readonly">${menuRoleShowByLine!}</textarea>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<epoch:winOpen id="selectRoleModal" title="分配角色" backdrop="true" width="800px">
    <epoch:table id="sysUserSelectRoleTable" queryUrl="${basePath}/sys/role/findRoleListAjax" rowId="id"
        autoAdjustWidth="false" onDelClick="onDelete" onAddClick="addClick" newBtn="false" delBtn="false" advBtn="false"
        selections="'${sysMenu.menuRole!}'" selectText="'${menuRoleShow!}'" selectName="role_name">
        <epoch:tr check="checkbox" titleTip="全选"></epoch:tr>
        <epoch:tr name="角色名称" formName="role_name"></epoch:tr>
        <epoch:tr name="描述" formName="comments"></epoch:tr>
        <epoch:tr name="状态" formName="status" filterType="select"
            filterData="${lisFun.dictForFilter('PUB_ENABLE_DISABLE')}"></epoch:tr>
        <epoch:tr name="角色类型" formName="role_type" filterType="select"
            filterData="${lisFun.dictForFilter('SYS_ROLE_TYPE')}"></epoch:tr>
    </epoch:table>
</epoch:winOpen>

<!--菜单选择-->
<epoch:winOpen id="selectMenuModal" title="选择父级菜单" backdrop="true"
            width="380px" height="550px">
    <div style="width:100%;height:100%;overflow-y:scroll;">
        <ul id="sysZrTreeBean" class="ztree"></ul>
    </div>
</epoch:winOpen>
<script type="text/javascript">
	
	_headToolBar.saveBtn(null, null, suv);
	
	//菜单组织树
	var zTreeObj;
	var setting = {
	    check: {chkStyle: "radio", enable: true, radioType: "all"},
	    data: {simpleData: {enable: true}},
	    callback: {onCheck: zTreeOnClick}
	};
	var zNodes = [{
	    name: "菜单树",
	    id: "-1",
	    open: true,
	    children:${treeNodeJson}
	}];
	$(document).ready(function () {
	    zTreeObj = $.fn.zTree.init($("#sysZrTreeBean"), setting, zNodes);
	});
	var ids = "";
	var idsName = "";
	function zTreeOnClick(event, treeId, treeNode) {
	    ids = treeNode.id;
	    idsName = treeNode.name;
	}
	
	
	$("#selectRoleModal_save").click(function() {
        var text = $("#sysUserSelectRoleTable_select_text").val();
        console.log(text)
        if (!isEmpty(text)) {
            var text_arr = text.split(",");
            text = text_arr.join("\r\n");
            $("#selectRoleText").val(text);
        } else {
            $("#selectRoleText").val("");
        }
        console.log(text)
        var ids = $("#sysUserSelectRoleTable_select_ids").val();
        if (!isEmpty(ids)) {
            $("#userRole").val(ids);
        } else {
            $("#userRole").val("");
        }
        $("#selectRoleModal").modal('hide');
    });
	
	$("#selectMenuModal_save").click(function() {
		if (isEmpty(ids)) {
        	MessageBox.error("请选择部门！");
            return false;
        }
        $("#fjcdName").val(idsName);
        $("#fjcd").val(ids);
        $("#selectMenuModal").modal('hide');
    });
	
	
	var flag = false;
    function suv(){
        if ($("#cdmc").val() == null || $("#cdmc").val() == '') {
            showErrorMessage("error-msg","菜单名称不能为空！");
            $("#cdmc").focus();
            return false;
        }
        if ($("#cdurl").val() == null || $("#cdurl").val() == '') {
            showErrorMessage("error-msg","菜单URL不能为空");
            $("#cdurl").focus();
            return false;
        }
        if ($("#cdss").val() == null || $("#cdss").val() == '') {
            showErrorMessage("error-msg","菜单序号不能为空");
            $("#cdss").focus();
            return false;
        } else {
            var regex = new RegExp("[0-9]{1,4}");
            if(!regex.test($("#cdss").val())){
                showErrorMessage("error-msg","菜单序号无效,必须是0-9999的整数！");
                $("#cdss").focus();
                return false;
            }
        }
        if ($("#cdlx").val() == null || $("#cdlx").val() == '') {
            showErrorMessage("error-msg","菜单类型不能为空");
            $("#cdlx").focus();
            return false;
        }
        if ($("#menuCodeId").val() == null || $("#menuCodeId").val() == '') {
            showErrorMessage("error-msg","菜单编码不能为空");
            $("#menuCodeId").focus();
            return false;
        }
        flag = true;
        if(flag){
            saveFun();
        }
	}
    
    function saveFun(){
    	$.ajax({
            url:"${basePath}/sys/menu/suv",
            data:$("form").serialize(),
            type:"post",
            success:function(result){
                if(result){
                    if(result.code=="0"){
                        MessageBox.success("保存成功。");
                        _tabs.showPage("sys_menu_list");
                    }else{
                        MessageBox.error("保存失败！");
                    }
                }else{
                     MessageBox.error("保存失败！");
                }
            },
            error:function(){
                MessageBox.error("服务器错误，请稍后再试！");
            },
            async:false
        });
    }

</script>